<?php

if (!defined('IN_XLP')) {
    exit('Access Denied!');
}

/**
 * Description of memberAction
 *
 * @author xlp
 */
class memberAction extends commonAction {

    function __construct() {
        parent::__construct();
        parent::_checkLogin();
        $this->sex = array('保密', '男', '女');
        $this->assign(array('sex' => $this->sex , 'vip' => array(1 => 'VIP1' , 2 => 'VIP2' , 3 => 'VIP3')));
    }


    /**
     * Description of memberAction
     * 会员列表
     * @author hsisme
     */
    function index() {
        $p = $this->_getid('p', 1);
        $keyword = $this->_get('keyword' , '');
        // $export = $this->_getid('export' , 0);
        $where = ' is_del = 0 ';
        if ($keyword) {
           $where.=" AND phone LIKE '%" . parent::safeSearch($keyword) . "%'";
        }
        $order = 'uid DESC';
        $pageShow = 20;
        $rs = M('user')->where($where)->page($p , $pageShow)->order($order)->findAll();

        $this->assign(array('rs' => $rs, 'p' => $p,'total' => M('user')->where($where)->count() , 'keyword' => $keyword));
        $this->display();
    }



    /**
     * Description of memberAction
     * 编辑会员
     * @author hsisme
     */
    function edit() {
        if(isAjax()) {
            $objData['user_level'] = $this->_postid('user_level' , 1);
            $objData['status'] = $this->_postid('status' , 0);
            $uid = $this->_postid('uid');
            if(M('user')->update($objData , ['uid' => $uid])) {
                $this->JsonReturn('ok' , null , 1);
            }else{
                $this->JsonReturn('编辑失败');
            }
        }else{
            $uid  = $this->_getid('uid' , 0);
            $user = M('user')->where(['uid' => $uid])->find();
            if(!$user) { showError("会员信息不存在"); }
            $this->assign('user' , $user);
            $this->display();
        }
    }

}
